<template>
  <the-table
    ref="table"
    :columns="columns"
    uri="/a/sellers"
    :slots="['enableSlot', 'action']"
  >
    <template slot="enableSlot" slot-scope="{ row }">
      {{ row.enable ? '启用' : '禁用' }}
    </template>
    <template slot="action" slot-scope="{ row }">
      <a class="ant-dropdown-link" @click="onEdit(row)"
        ><a-icon type="edit" /> 编辑
      </a>
      <a class="ant-dropdown-link ml-2" @click="onCoins(row)"
        ><a-icon type="pay-circle" /> 加减币
      </a>
      <a-divider type="vertical" v-if="isNo1" />
      <a class="ant-dropdown-link red" v-if="isNo1" @click="onClean(row)"
        ><a-icon type="delete" /> 清理
      </a>
      <a class="ant-dropdown-link red ml-2" @click="onCleanGa(row)"
        ><a-icon type="delete" /> 清理谷歌验证
      </a>
      <a class="ant-dropdown-link red ml-2" @click="onCleanWhitelist(row)"
        ><a-icon type="delete" /> 清理白名单
      </a>
    </template>
  </the-table>
</template>
<script>
import theTable from '@/components/theTable.vue'

const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 55,
  },
  {
    title: '商户编号',
    dataIndex: 'code',
    searchAble: true,
  },
  {
    title: '商户名',
    dataIndex: 'username',
    searchAble: true,
  },
  {
    title: '联系方式',
    dataIndex: 'mobile',
  },
  {
    title: '可动币值',
    dataIndex: 'coins',
  },
  {
    title: '买币手续费',
    dataIndex: 'fee_ratio',
  },
  {
    title: '下发手续费',
    dataIndex: 'tip',
  },
  {
    title: '注册时间',
    dataIndex: 'created_at',
    dataType: 'range',
    searchAble: true,
  },
  {
    title: '最近登录时间',
    dataIndex: 'login_at',
  },
  {
    title: '最近登录IP',
    dataIndex: 'login_ip',
  },
  {
    title: '状态',
    dataIndex: 'enable',
    scopedSlots: { customRender: 'enableSlot' },
  },
  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
    // width: 80,
  },
]

export default {
  components: { theTable },

  data() {
    return {
      columns,
    }
  },
  computed: {
    isNo1() {
      return this.$store.state.account.user.id == 1
    },
  },
  methods: {
    onEdit(row) {
      this.$emit('on-edit', row)
    },
    onCoins(row) {
      this.$emit('on-coins', row)
    },
    onClean(row) {
      this.axios.delete(`/sellers/${row.id}`).then((res) => {
        this.$message.success('清理成功')
      })
    },
    onCleanGa(row) {
      this.axios.delete(`/a/sellers/${row.id}/ga`).then((res) => {
        this.$message.success('清理成功')
      })
    },
    onCleanWhitelist(row) {
      this.axios.delete(`/a/whitelist?uid=${row.id}`).then((res) => {
        this.$message.success('清理成功')
      })
    },
  },
}
</script>
